//
// Service Extension to add Utility Functions
//
// NOTE: Service Extensions do not appear to work as anticipated!
//
// This code is currently BROKEN!!! See GenericBrickUtil instead.
//
using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Dss.ServiceModel.DsspServiceBase;


#if DSSPROXY
using brick = ProMRDS.Robotics.GenericBrick.Proxy;

namespace ProMRDS.Robotics.GenericBrick.Proxy
#else
using brick = ProMRDS.Robotics.GenericBrick;

namespace ProMRDS.Robotics.GenericBrick
#endif
{

    /// <summary>
    /// Utility Functions for Generic Brick
    /// </summary>
    public class Util
    {
        /// <summary>
        /// Find a Device by Hardware Id
        /// </summary>
        /// <param name="list"></param>
        /// <param name="id"></param>
        /// <returns>Index if found or -1 if not</returns>
        public static int FindDeviceById(List<brick.Device> list, int id)
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].HardwareIdentifer == id)
                    return i;
            }
            // Not found!
            return (-1);
        }

        /// <summary>
        /// Is this an Analog Device?
        /// </summary>
        /// <param name="dev"></param>
        /// <returns>True if Analog, False if not</returns>
        public static bool IsAnalogDevice(brick.Device dev)
        {
            if (((dev.Type & brick.DeviceTypes.AnalogIn) != 0) ||
                ((dev.Type & brick.DeviceTypes.AnalogOut) != 0))
                return true;
            else
                return false;
        }

        /// <summary>
        /// Is this a Digital Device?
        /// </summary>
        /// <param name="dev"></param>
        /// <returns>True if Digital, False if not</returns>
        public static bool IsDigitalDevice(brick.Device dev)
        {
            if (((dev.Type & brick.DeviceTypes.DigitalIn) != 0) ||
                ((dev.Type & brick.DeviceTypes.DigitalOut) != 0) ||
                ((dev.Type & brick.DeviceTypes.DigitalInOut) != 0))
                return true;
            else
                return false;
        }

    }
}
